﻿package fwk.form.elements 
{
	import flash.text.TextField;
	import flash.display.MovieClip;
	
	/**
	 * ...
	 * @author DefaultUser (Tools -> Custom Arguments...)
	 */
	public class QuestionDateText extends AbstractQuestion 
	{
		
		private var _champsDay:TextField;
		private var _champsMonth:TextField;
		private var _champsYear:TextField;
		
		private var _dateChaine:String;
		private var _date:Date;
		
		
		private var _reponseDay:AbstractReponse;
		private var _reponseMonth:AbstractReponse;
		private var _reponseYear:AbstractReponse;
		
		public function get reponseDay():AbstractReponse
		{
			_reponseDay.value 		= _champsDay.text;
			return _reponseDay;
		}
		public function get reponseMonth():AbstractReponse
		{
			_reponseMonth.value 		= _champsMonth.text;
			return _reponseMonth;
		}
		public function get reponseYear():AbstractReponse
		{
			_reponseYear.value 		= _champsYear.text;
			return _reponseYear;
		}
		public function get date():Date
		{
			
			_reponseDay.value 		= _champsDay.text;
			_reponseMonth.value 	= _champsMonth.text;
			_reponseYear.value 		= _champsYear.text;
			
			
			_date = new Date(parseInt(reponseYear.value), parseInt(reponseMonth.value) - 1, parseInt(reponseDay.value));
			trace("date " + _date);
			return _date;
		}
		public function get dateChaine():String
		{
			_reponseDay.value 		= _champsDay.text;
			_reponseMonth.value 	= _champsMonth.text;
			_reponseYear.value 		= _champsYear.text;
			
			_dateChaine = reponseDay.value + "-" + reponseMonth.value + "-" + reponseYear.value;
			
			return _dateChaine;
		}
		
		public function QuestionDateText(mc:MovieClip = null) 
		{

			super(mc);
			
		}
		public function init(xmlConfig:XML, champsDay:TextField, champsMonth:TextField, champsYear:TextField)
		{
			
			super._init(xmlConfig);
			
			_champsDay 		= champsDay;
			_champsMonth 	= champsMonth;
			_champsYear 	= champsYear;
			
			_reponseDay 		= new AbstractReponse();
			_reponseMonth 		= new AbstractReponse();
			_reponseYear 		= new AbstractReponse();
			
			_reponseDay.id 			= xmlConfig.day.@id;
			_reponseMonth.id 		= xmlConfig.month.@id;
			_reponseYear.id 		= xmlConfig.year.@id;
			
			_reponseDay.valueInitial 		= _champsDay.text;
			_reponseMonth.valueInitial 		= _champsMonth.text;
			_reponseYear.valueInitial 		= _champsYear.text;
			
		}
		override public function reset():void 
		{
			hideError();
			
			_champsDay.text = _reponseDay.valueInitial;
			_champsMonth.text = _reponseMonth.valueInitial;
			_champsYear.text = _reponseYear.valueInitial;	
			
			_reponseDay.value 		= _champsDay.text;
			_reponseMonth.value 	= _champsMonth.text;
			_reponseYear.value 		= _champsYear.text;
		}
		
		
		
		
		override public function get reponsesTab():Array
		{
			_reponseDay.value 		= _champsDay.text;
			_reponseMonth.value 	= _champsMonth.text;
			_reponseYear.value 		= _champsYear.text;
			
		
			var repTab = new Array();
			repTab.push(_reponseDay);
			repTab.push(_reponseMonth);
			repTab.push(_reponseYear);
			
			return repTab;
			
		}
	}
	
}